# -*- coding: utf-8 -*-
import os


def open_txt(file_name):
    with open(file_name, 'r') as f:
        try:
            line = f.readline()
            while line:
                yield line.strip()
                line = f.readline()
        except:
            print('No value')


"""生成特定labels的charset同时消除多余数据"""
path = '/data1/mjh/datasets/SROIE/detection/labels.txt'
mc_list = []
mc_set = ()

# for file in os.listdir(path):
#     file_path = os.path.join(path, file)
#     for text in open_txt(file_path):
#         line = list(text.strip())
#         mc_set = set(list(mc_set) + line)

for line in open_txt(path):
    line = list(line.split('\t')[1].strip())
    for c in line:
        mc_list.append(c)

    # mc_set = set(list(mc_set) + line)
mc_set = set(mc_list)
charset = open('/data1/mjh/datasets/SROIE/detection/dicts.txt', 'w')
for item in mc_set:
    print(item)
    charset.writelines(str(item).strip() + '\n')
print(mc_set)